package com.hex.dmp;

import cn.hutool.json.JSONUtil;
import com.hex.dmp.license.AbstractServerInfos;
import com.hex.dmp.license.LinuxServerInfos;
import com.hex.dmp.license.WindowsServerInfos;
import java.io.FileWriter;
import java.io.IOException;

public class Main {

  public static void main(String[] args) {
    //操作系统类型
    String  osName = System.getProperty("os.name");
    osName = osName.toLowerCase();

    AbstractServerInfos abstractServerInfos = null;

    //根据不同操作系统类型选择不同的数据获取方法
    if (osName.startsWith("windows")) {
      abstractServerInfos = new WindowsServerInfos();
    } else if (osName.startsWith("linux")) {
      abstractServerInfos = new LinuxServerInfos();
    }else{//其他服务器类型
      abstractServerInfos = new LinuxServerInfos();
    }

   writeToFile(JSONUtil.toJsonStr(abstractServerInfos.getServerInfos()),"server_info.txt");
  }

  private static void writeToFile(String data, String filename) {
    try (FileWriter writer = new FileWriter(filename)) {
      writer.write(data);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}